<template>
  <div id="Service">
    <div class="container text-center">
      <h3>企业新闻</h3>
    </div>
    <div class="container">
      <div class="Service-container row">
        <div class="Service-item col-xs-12 col-sm-6 col-md-3 wow slideInUp" v-for="(item, index) in serviceList"
          :key="index" @click="ServiceClick(item.id)">
          <div class="Service-item-wrapper">

            <div class="Service-item-img">
              <img :src="item.listTitleImg" alt="服务" />
            </div>
            <div class="Service-item-top">
              <h4>{{ item.listTitle }}</h4>
              <!-- <i></i> -->
              <!-- <p>{{ item.eng_title }}</p> -->
            </div>
            <!-- <div class="Service-item-border"></div> -->
          </div>
        </div>
      </div>
      <div class="pagination-box">
        <div v-if="total" class="example-pagination-block">
          <!-- {{ pageCount }} -->
          <el-pagination layout="prev, pager, next" :total="total" :page-count="pageCount"
            @size-change="handleSizeChange" @current-change="handleCurrentChange" />
        </div>
      </div>
    </div>
  </div>
</template>
<script setup name="NewsInformation">
import axios from '../utils/axios';
import { useRouter } from 'vue-router'
import { ref, onMounted } from 'vue'
import WOW from 'wow.js'
import service1 from '@/assets/img/2024_hospital_4.jpg'
import service2 from '@/assets/img/2024_nerve_5.jpg'
import service3 from '@/assets/img/2024_Annual Meeting of Clinical Medicine_1.jpg'
import service5 from '@/assets/img/2024.6.15-1_New_Quality_Productive.jpg'
const router = useRouter();

const serviceList = ref([]);
const total = ref(null);
const pageSize = ref(6); // 设置请求: 每页显示多少条数据
const pageCount = ref(null); // 计算出的页数


/* const serviceList = [
  {
    id: 'section-1',
    title: '上海-2024公立医院绩效考核思考汇会议',
    eng_title: 'Technological Innovation and Research',
    img: service1,
    page: "1"
  },
  {
    id: 'section-2',
    title: '广州-第四届华南神经外科论坛',
    eng_title: 'Successful cases of clinical application',
    img: service2,
    page: "2"
  },
  {
    id: 'section-3',
    title: '上海-第十九届上海市医学会临床医学工程分会学术年会',
    eng_title: 'Remote diagnosis and treatment',
    img: service3,
    page: "3"
  },
  {
    id: 'section-5',
    title: '上海-第一届（2024）中国医疗器械新质生产力大会',
    eng_title: 'The First (2024) China New Quality Productive Forces Conference of Medical Devices',
    img: service5,
    page: "5"
  },
  {
    id: 'section-1',
    title: '上海-2024公立医院绩效考核思考汇会议',
    eng_title: 'Technological Innovation and Research',
    img: service1,
    page: "1"
  },
  {
    id: 'section-2',
    title: '广州-第四届华南神经外科论坛',
    eng_title: 'Successful cases of clinical application',
    img: service2,
    page: "2"
  },
  {
    id: 'section-3',
    title: '上海-第十九届上海市医学会临床医学工程分会学术年会',
    eng_title: 'Remote diagnosis and treatment',
    img: service3,
    page:"3"
  }
  ,{
    id: 'section-4',
    title: '上海-2024公立医院绩效考核思考汇会议',
    eng_title: 'Improve accessibility of medical services',
    img: service4,
    page:"4"
  },
] */


// function ServiceClick(id,page) {
//   router.push({
//     name: `/ServiceDetail${page}`,
//     state: {
//       id
//     }
//   })
// }


function ServiceClick(id) {
  // router.push({ name: "Detail", params: { id } });
  router.push(`/newsdetail/${id}`)
  // router.push(`/ServiceDetail${id}`)
}

const handleSizeChange = (val) => {
  console.log(`${val} items per page`)
}
const handleCurrentChange = (val) => {
  console.log(`current page: ${val}`)
  getDataList(val)
}

const getDataList = async (val) => {
  const res = await axios.get('/gwht/gw/xwdt/list', {
    params: {
      pageNum: val,
      pageSize: pageSize.value
    }
  });
  console.log(res, 'res==');

  serviceList.value = res.rows;
  total.value = res.total;
  pageCount.value = getPageCount(res.total, pageSize.value);
}

// 计算页数
function getPageCount(total, n) {
  if (n <= 0) return 0; // 避免除数为0
  return Math.ceil(total / n);
}

onMounted(() => {
  var wow = new WOW()
  wow.init()

  // 
  // getDataList();
  handleCurrentChange(1)
})
</script>


<style scoped>
.example-pagination-block+.example-pagination-block {
  margin-top: 10px;
}

.example-pagination-block .example-demonstration {
  margin-bottom: 16px;
}

.pagination-box {
  display: flex;
  justify-content: flex-end;
  transform: translate(-36px, -30px);
}

@media (min-width: 992px) {
  .col-md-3 {
    width: 33.3%;
  }
}

.Service-container {
  padding: 30px 50px;
}

.Service-item {
  margin-bottom: 50px;

}

.Service-item-wrapper {
  cursor: pointer;
  background: rgba(244, 244, 244, 1);
  overflow: hidden;
  position: relative;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  overflow: hidden;
}

.Service-item-wrapper:hover {
  border: 1px solid transparent;

}

.Service-item-top {
  width: 100%;
  height: 120px;
  padding: 30px;
  /* text-align: center; */
}

.Service-item-top>i {
  display: inline-block;
  width: 25px;
  height: 2px;
  background: #28f;
}

.Service-item-top>p {
  color: #b2b2b2;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.5s ease;
}

.Service-item-img {
  width: 100%;
  overflow: hidden;
}

.Service-item-img img {
  width: 100%;
  transition: all 0.5s ease;
  /* height: 150px; */
  height: 246px;
}

.Service-item-border {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  z-index: 9999999;
  width: 100%;
  height: 100%;
  transition: all 0.5s ease;
  border: 1px solid #000;
  opacity: 0;
}

.Service-item-top>h4 {
  font-size: 18px;
  color: #222;
  margin-bottom: 10px;
  transition: all .3s;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  line-height: 26px;
  height: 52px;
}

.Service-item-wrapper:hover .Service-item-top>i {
  opacity: 0;
}

.Service-item-wrapper:hover .Service-item-top>p {
  opacity: 1;
  transform: translateY(-10px);
}

.Service-item-wrapper:hover .Service-item-img>img {
  transform: scale(1.1, 1.1);
}

.Service-item-wrapper:hover>.Service-item-border {
  opacity: 1;
  width: 90%;
  height: 90%;
}

.Service-item-wrapper:hover {
  /* box-shadow: 2px 4px 24px 0 #a5a3a3; */
  box-shadow: 6px 6px 24px 6px #a5a3a3;
}
</style>
